class Solution {
public:
    long long pre = LONG_MIN;
    bool isValidBST(TreeNode* root) {
        if (root == nullptr) return true;
        bool left = isValidBST(root->left);
        if (!left) return false;
        if (root->val <= pre) return false;
        else pre = root->val;
        bool right = isValidBST(root->right);
        return left && right;
    }
};